import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      redirect: '/login',
    },
    {
      path: '/login',
      name: 'Login',
      component: () => import(/* webpackChunkName: "login" */ '_v/Login.vue'),
      meta: { title: '登录' }
    },
    {
      path: '/register',
      name: 'Register',
      component: () =>
        import(/* webpackChunkName: "register" */ '_v/Register.vue'),
      meta: { title: '注册' }
    },
    {
      path: '/file',
      name: 'File',
      component: () => import(/* webpackChunkName: "file" */ '_v/File.vue'),
      meta: {
        requireAuth: true, //  当前路由是否需要登录才可进入
        title: '网盘',
        content: {
          description: '图片 文档 视频 音乐 其他 回收站 我的分享'
        }
      }
    },
    {
      path: '/root',
      name: 'Root',
      component: () => import(/* webpackChunkName: "file" */ '_v/Root.vue'),
      meta: { title: '系统管理员', requireAuth: true }
    },
    {
      path: '*',
      name: 'Error_404',
      component: () =>
        import(/* webpackChunkName: "error_404" */ '_v/ErrorPage/404.vue'),
      meta: { title: '链接不存在' }
    }
  ]
})

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}
